﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Frame.Lib.Common
{
    public sealed class AppCookie
    {
        private static System.Web.HttpContext Current
        {
            get
            {
                return System.Web.HttpContext.Current;
            }
        }

        public static string LoginName
        {
            get
            {
                return (Current.Request.Cookies["LoginName"] == null) ? null : Current.Server.UrlDecode(Current.Request.Cookies["LoginName"].Value);
            }
            set
            {
                HttpCookie cookie = new HttpCookie("LoginName", Current.Server.UrlEncode(value));
                cookie.Expires = DateTime.Now.AddHours(10);
                Current.Response.Cookies.Add(cookie);
            }
        }

        public static string CompanyLoginName
        {
            get
            {
                return (Current.Request.Cookies["CompanyLoginName"] == null) ? null : Current.Server.UrlDecode(Current.Request.Cookies["CompanyLoginName"].Value);
            }
            set
            {
                HttpCookie cookie = new HttpCookie("CompanyLoginName", Current.Server.UrlEncode(value));
                cookie.Expires = DateTime.Now.AddHours(10);
                Current.Response.Cookies.Add(cookie);
            }
        }

        public static string Password
        {
            get
            {
                return (Current.Request.Cookies["Password"] == null) ? null : Current.Request.Cookies["Password"].Value;
            }
            set
            {
                HttpCookie cookie = new HttpCookie("Password", value);
                cookie.Expires = DateTime.Now.AddHours(10);
                Current.Response.Cookies.Add(cookie);

            }
        }

        public static void Clear()
        {
            HttpCookie cookie = new HttpCookie("LoginName");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Current.Response.Cookies.Add(cookie);

            cookie = new HttpCookie("Password");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Current.Response.Cookies.Add(cookie);

            cookie = new HttpCookie("CompanyLoginName");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Current.Response.Cookies.Add(cookie);
        }
    }
}
